package com.sbw.application.scaffold.controller;

import com.oyo.common.enums.ResponseCode;
import com.oyo.common.response.BaseResponse;
import com.sbw.application.scaffold.common.enums.ReportResponseCode;
import com.sbw.application.scaffold.controller.request.BizRevenueSearchRequest;
import com.sbw.application.scaffold.controller.request.PostingDetailSearchRequest;
import com.sbw.application.scaffold.controller.vo.BizRevenueReportVO;
import com.sbw.application.scaffold.controller.vo.PostingDetailVO;
import com.sbw.application.scaffold.service.HotelPostingDetailService;
import com.sbw.application.scaffold.service.HotelBizRevenueReportService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author sangbowei
 */
@RestController
@RequestMapping("/report")
@Slf4j
public class ReportController {

	@Resource
	private HotelPostingDetailService postingDetailService;

	@Resource
	private HotelBizRevenueReportService bizRevenueReportService;

	/**
	 * 功能描述: 查询酒店每日营收报表
	 * @param searchRequest
	 * @return: BaseResponse
	 * @auther: sangbowei
	 * @date: 2018/8/28 15:11
	 */
	@RequestMapping(value = "/findBizRevenueReportList", method = RequestMethod.POST)
	public BaseResponse findBizRevenueReportList(@RequestBody BizRevenueSearchRequest searchRequest) {

		if (null == searchRequest) {
			return BaseResponse.fail(ResponseCode.FAILURE.getCode(), ReportResponseCode.INVALID_PARAMS.getMsg());
		}

		// 对外接口暂时不允许跨酒店查询
		Long hotelId = searchRequest.getHotelId();
		if(null == hotelId){
			return BaseResponse.fail(ResponseCode.FAILURE.getCode(), ReportResponseCode.HOTEL_ID_IS_NULL.getMsg());
		}

		List<BizRevenueReportVO> bizRevenueReportVOS = bizRevenueReportService.findBizRevenueReportList(searchRequest);
		return BaseResponse.success(bizRevenueReportVOS);
	}

	/**
	 * 功能描述: 查询账务详情列表
	 * @param searchRequest
	 * @return: BaseResponse
	 * @auther: sangbowei
	 * @date: 2018/8/28 18:02
	 */
	@RequestMapping(value = "/findPostingDetailList", method = RequestMethod.POST)
	public BaseResponse findPostingDetailList(@RequestBody PostingDetailSearchRequest searchRequest) {

		if (null == searchRequest) {
			return BaseResponse.fail(ResponseCode.FAILURE.getCode(), ReportResponseCode.INVALID_PARAMS.getMsg());
		}

		// 对外接口暂时不允许跨酒店查询
		Long hotelId = searchRequest.getHotelId();
		if(null == hotelId){
			return BaseResponse.fail(ResponseCode.FAILURE.getCode(), ReportResponseCode.HOTEL_ID_IS_NULL.getMsg());
		}

		List<PostingDetailVO> postingDetailList = postingDetailService.findPostingDetailList(searchRequest);
		return BaseResponse.success(postingDetailList);
	}

}